<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>修改密码 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="/ssm/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/ssm/static/css/materialdesignicons.min.css" rel="stylesheet">
<link href="/ssm/static/css/style.min.css" rel="stylesheet">
  <link href="/ssm/static/css/animate.css" rel="stylesheet">
  <style>
    #userId{
      display: none;
    }
  </style>
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form class="site-form">
            <div id="userId"></div>
            <div class="form-group">
              <label for="old-password">旧密码</label>
              <input type="password" class="form-control" name="oldpwd" id="old-password" placeholder="输入账号的原登录密码" autocomplete="off">
            </div>
            <div class="form-group">
              <label for="new-password">新密码</label>
              <input type="password" class="form-control" name="newpwd" id="new-password" placeholder="输入新的密码" autocomplete="off">
            </div>
            <div class="form-group">
              <label for="confirm-password">确认新密码</label>
              <input type="password" class="form-control" name="confirmpwd" id="confirm-password" placeholder="请再次输入新的密码" autocomplete="off">
            </div>

          </form>
          <button class="btn btn-primary" id="onSavePassword">修改密码</button>
        </div>
      </div>
    </div>
    
  </div>
  
</div>

<script type="text/javascript" src="/ssm/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/ssm/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/ssm/static/js/main.min.js"></script>
<!--消息提示-->
<script src="/ssm/static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/ssm/static/js/lightyear.js"></script>
<script type="text/javascript">
    let token = localStorage.getItem("token");
    if (token===null){
      token = sessionStorage.getItem("token");
    }

    $.ajax({
      type: "GET",
      url: "/ssm/user/user/info",
      dataType: "json",
      header:{
        'Authorization':token
      },
      beforeSend : function(request) {
        request.setRequestHeader("Authorization",token );
      },
      success:(res)=>{
        if(res.code===20000){
          $("#userId").append(res.data.userId)
        }
      }

    });
    $("#onSavePassword").click(()=>{
      lightyear.loading('show');
      let old_password = $("#old-password").val();
      let new_password = $("#new-password").val();
      let confirm_password = $("#confirm-password").val();
      if(old_password===''){
        lightyear.loading('hide');
        lightyear.notify('旧密码为空~', 'warning', 3000);
      }else if(new_password===''){
        lightyear.loading('hide');
        lightyear.notify('新密码为空~', 'warning', 3000);
      }else if(confirm_password===''){
        lightyear.loading('hide');
        lightyear.notify('确认新密码为空~', 'warning', 3000);
      }else{
        if(new_password===confirm_password){
          $.ajax({
            type: 'POST',
            url:'/ssm/user/user/pw',
            data:{
              userId: $("#userId").text(),
              originPassword: old_password,
              newPassword:new_password,
              _method: 'PATCH'
            },
            dataType: 'json',
            success:(res)=>{
              if(res.code===20000){
                lightyear.loading('hide');
                lightyear.notify('修改密码成功~', 'success', 3000);
              }else if(res.code===205){
                lightyear.loading('hide');
                lightyear.notify(res.msg+'，请检查后重新输入~', 'warning', 3000);
              }else{
                lightyear.loading('hide');
                lightyear.notify('修改密码失败~', 'danger', 3000);
              }
            }
          })
        }else{
          lightyear.loading('hide');
          lightyear.notify('两次输入密码不一致，请检查后重新输入~', 'warning', 3000);
        }
      }

    });






</script>
</body>
</html>